class_name PlayStatusManage extends Node

########################## 有限状态机模型
var status_map : Dictionary
var status_msg : Dictionary

var current_status:int
var current_status_before :int 

# 当前运行的节点
var current_node;

func change_status(next_status:int):
	if next_status != current_status:
		#1. 初始化新状态
		var next_node = get_status_node(next_status)
		next_node.start()
		
		#2. 结束旧状态
		current_node.stop()
		
		#3. 指向新状态
		current_node = next_node
		
		#4. 状态变更
		current_status_before = current_status
		current_status = next_status
		
		# 打印状态变更
		var msg :String
		msg = get_status_msg(current_status_before)
		print("%s has stop" % msg);

		msg = get_status_msg(current_status)
		print("%s start" % msg)

func set_default(set_status:int):
	current_status_before =  set_status
	current_status =  set_status
	current_node = get_status_node(set_status)
	#start_status_node(set_status)
	
func add_status_node(current_status, node, info ):
	status_map[current_status] = node
	status_msg[current_status] = info
	node.manage_node = self

func get_status_node(local_status:int):
	return status_map.get(local_status)
	
################# 打印当前的状态值
func print_current_status():
	if current_status_before == current_status:
		return
	var msg = get_status_msg(current_status)

func is_status(status:int) -> bool:
	return status == current_status

func get_status()->int:
	return current_status
	
func get_status_msg(current_status):
	return status_msg.get(current_status)
